package com.example.starterdemo;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.Charsets;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @description:
 * @author: dengPing.xu
 * @date: 2022-08-08
 */
public class FileRead {


    public static void main(String[] args) {
        File file = FileUtil.file("E:\\BaiduNetdiskDownload\\【马老师】Java高级互联网架构师\\01-精英1班\\精英一班等学习顺序参考【空目录】");
        if(!file.isDirectory()) {
            return;
        }
        StringBuilder sb = new StringBuilder();
        File[] files = file.listFiles();
        for (File item : files) {
            sb.append(item.getName()).append("\t");
            File[] files1 = item.listFiles();
            for (File file1 : files1) {
                sb.append(file1.getName()).append(" ");
            }
            sb.append("\n");
        }
        System.out.println(sb.toString());

    }

    private static void extractedJson() {
        File file = FileUtil.file("D:\\Desktop\\new 2.txt");
        List<String> list = FileUtil.readLines(file, StandardCharsets.UTF_8);
        StringBuilder sb = new StringBuilder();
        list.forEach(sb::append);
        String json = sb.toString();
        System.out.println(json);
        JSONArray objects = JSONArray.parseArray(json);


        File resultFile = FileUtil.touch("D:\\Desktop\\result-2.txt");
        for (Object object : objects) {
            JSONObject jsonObject = JSON.parseObject(String.valueOf(object));
            FileUtil.appendString(jsonObject.get("onebest").toString() + "\n", resultFile, StandardCharsets.UTF_8);
        }
    }
}
